package com.aotain.project.apollo.app;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

import com.aotain.common.ZkKafkaConfig;
import com.aotain.hbase.HBaseDao;

public class IdcAttackIps {

	private static String _zkServer = "192.168.5.95,192.168.5.96,192.168.5.97";
//	private static String _logServer = "192.168.5.95:9529";
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdf_ = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
//		Calendar cl = Calendar.getInstance();
//		cl.add(Calendar.DAY_OF_MONTH, 1);
//		String endDateStr = sdf.format(cl.getTime());
		String startDateStr = sdf.format(date);
		String startRow = "";
		String endRow = "";
		ZkKafkaConfig z_kConfig = new ZkKafkaConfig("/home/storm/config/dbconfig.ini");
		_zkServer = z_kConfig.getZkConnServer();
		System.out.println(_zkServer);
		String tableName_1 = "SDS_ABN_SESS_STAT_IDC_D";
		String tableName_2 = "SDS_IDC_STAT_D";
		List<String> idcnoList = new ArrayList<String>();
		
		int dosSiteNum = 0;
		int ccSiteNum = 0;
		
		HBaseDao dao = new HBaseDao(_zkServer);
//		HBaseRecordAdd hbaseInstance = HBaseRecordAdd.getInstance(
//				_zkServer,_logServer);
		
		idcnoList = IdcDao.getInstance().getIdcNo();
		System.out.println("idcnoList's size =" + idcnoList.size());
		for(Iterator<String> iter = idcnoList.iterator();iter.hasNext();) {
			String idcno = iter.next();
			startRow = startDateStr + "_" + idcno;
			endRow = startDateStr + "_" + idcno + "|";
			dosSiteNum = dao.getAssignColumnNum(tableName_1, startRow, endRow, "DOS");
			ccSiteNum = dao.getAssignColumnNum(tableName_1, startRow, endRow, "CC");
			System.out.println("CurrentTime:"+ sdf_.format(date) + ":startrow: " + startRow + " dosSiteNum: " + dosSiteNum + " ccSiteNum: " + ccSiteNum);
			dao.insert(tableName_2, startRow, "cf", "DOSSITENUM", String.valueOf(dosSiteNum));
			dao.insert(tableName_2, startRow, "cf", "CCSITENUM", String.valueOf(ccSiteNum));
			dao.insert(tableName_2, startRow, "cf", "REPORTTIME", startDateStr);
			dao.insert("test", startRow, "cf", "DOSSITENUM", String.valueOf(dosSiteNum));
			dao.insert("test", startRow, "cf", "CCSITENUM", String.valueOf(ccSiteNum));
		}
		
		Logger.getRootLogger().error("CurrentTime:"+ sdf_.format(date) + "startrow:" + startDateStr + " endrow:" + endRow +" dosSiteNum:" + dosSiteNum + "ccSiteNum" + ccSiteNum);
	}

}
